/*
 * Copyright 2010 Michael Nitsche
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package de.mnit.basis.swt.element.steuer.rollbar.gruppe;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Spinner;

import de.mnit.basis.fehler.Fehler;
import de.mnit.basis.swt.element.steuer.rollbar.gruppe.A_SWT_Gruppe;

/**
 * @author Michael Nitsche
 */
public class SWT_Zaehler extends A_SWT_Gruppe<SWT_Zaehler,Spinner> {

	private boolean nur_lesen=false;


	public SWT_Zaehler s1_NurLesen() {
		this.PN_Erzeugt();
		this.nur_lesen=true;
		return this;
	}

	// FUNKTION

	public SWT_Zaehler sMinMax(int min, int max) {
		Fehler.zahl.wenn_ZuKlein(min+1,max);
		this.swt().setMaximum(max);
		this.swt().setMinimum(min);
		return this;
	}

	public SWT_Zaehler sWert(int wert) {
		Fehler.zahl.wenn_Ausserhalb(swt().getMinimum(),swt().getMaximum(),wert);
		this.swt().setSelection(wert);
		return this;
	}

	// LESEN

	public int gWert()   { return swt().getSelection(); }
	public int gMin()    { return swt().getMinimum(); }
	public int gMax()    { return swt().getMaximum(); }

	// ERZEUGEN

	protected int style5() {
		return nur_lesen ? SWT.READ_ONLY : SWT.NONE;
	}

	protected Spinner roh(Composite basis, int style) {
		return new Spinner(basis,style);
	}

	protected void init5() {}

}
